package com.tepth.busfix;

import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;

import com.shadow.bus.RootDelegate;
import com.shadow.bus.config.NetState;
import com.shadow.bus.event.CheckVersionEvent;
import com.tencent.bugly.beta.Beta;
import com.zhangyu.shadow.core.activity.ProxyActivity;
import com.zhangyu.shadow.core.delegate.ShadowDelegate;
import com.zhangyu.shadow.core.net.receiver.NetBroadcastReceiver;
import com.zhangyu.shadow.core.util.net.NetworkUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

public class MainActivity extends ProxyActivity {

    NetBroadcastReceiver mNetBroadcastReceiver;

    @Override
    public ShadowDelegate setRootDelegate() {
        return RootDelegate.newInstance();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        mNetBroadcastReceiver = new NetBroadcastReceiver(new NetBroadcastReceiver.OnNetChangeListener() {
            @Override
            public void onNetChange() {
                NetState.IS_NET_CONNECT = NetworkUtils.isConnected();
            }
        });
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(mNetBroadcastReceiver, intentFilter);
    }

    @Subscribe
    public void onCheckVersionEvent(CheckVersionEvent event) {
        Beta.checkUpgrade(true, false);
    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        //  FingerManager.getInstance().close();
        unregisterReceiver(mNetBroadcastReceiver);
        super.onDestroy();
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        getSupportFragmentManager().beginTransaction().commit();
    }
}
